from pathlib import Path

from tools.处理excel import 筛选excel
from tools.微信QQ发送文件 import QQ_send_msg, wechat_send_msg


def 分发(date='2024-04-04'):
    name_list = [['上海邮政'], ['昆山邮政'], ['南昌韵达'], ["南昌邮政"], ['南昌申通'], ['南昌德邦'], ['京东'],
                 ['中通', '昌东'],
                 ['中通', '三部'], ['义乌中通'], ['南昌极兔']]
    # name_list = [
    #              ['中通', '昌东'],
    #              ['中通', '三部'], ['义乌中通'], ['南昌极兔'], ['义乌极兔', '城西'], ['义乌极兔', '新疆|西藏']]
    快递_dict = {'上海邮政': '上海邮政群', '昆山邮政': '昆山邮政群', '南昌邮政': '南昌邮政群', '南昌韵达': '南昌韵达群',
                 '南昌申通': '南昌申通群', '南昌德邦': '南昌德邦群',
                 '京东': '南昌京东群', '中通-昌东': '南昌中通昌东站点客服群昀晗机器人', '中通-三部': '南昌中通三部群',
                 '义乌中通': '义乌中通群', '南昌极兔': '南昌极兔群'}
    filepath = f"D:\\快递赔付\\{date}\\快递赔付.xlsx"
    for name in name_list:
        if len(name) > 1:
            快递name = f"{name[0]}-{name[1].replace('|', '')}"
            outpath = f"D:\\快递赔付\\{date}\\{name[0]}-{name[1].replace('|', '')}.xlsx"
            筛选excel(filepath, name, outpath)
        else:
            快递name = f"{name[0]}"
            outpath = f"D:\\快递赔付\\{date}\\{name[0]}.xlsx"
            筛选excel(filepath, name, outpath)
        if Path(outpath).exists() and 快递name in ['南昌申通', '义乌中通']:
            QQ_send_msg(快递_dict[快递name], outpath)
        elif Path(outpath).exists() and 快递name == '南昌德邦':
            QQ_send_msg(快递_dict[快递name], outpath)
        elif Path(outpath).exists() and 快递name in ['中通-昌东', '南昌极兔']:
            wechat_send_msg(快递_dict[快递name], outpath)
        # elif Path(outpath).exists() and 快递name in ['南昌韵达']:
        #     wechat_send_file(快递_dict[快递name], outpath)
        elif Path(outpath).exists():
            wechat_send_msg(快递_dict[快递name], outpath)

# 分发()
